package com.lemon.ai.socket.packets.spiritgame.xls2Object;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

import com.lemon.ai.socket.packets.spiritgame.xls2Object.generator.ASClassGenerator;
import com.lemon.ai.socket.packets.spiritgame.xls2Object.generator.ASClassModelGenerator;
import com.lemon.ai.socket.packets.spiritgame.xls2Object.generator.JavaClassGenerator;
import com.lemon.ai.socket.packets.spiritgame.xls2Object.generator.JavaConfigClassGenerator;
import com.lemon.ai.socket.packets.spiritgame.xls2Object.generator.XmlGenerator;




public class ExcelParser {
	private static final String PATH = "D:\\eclipse4\\eclipse\\workspace\\InternetFiles\\策划资料\\数值\\";
	public static void main(String[] args) throws Exception {
		File f = new File(PATH);
		String[] list = f.list();
		for (String fileName : list) {
			String className = fileName.replace(".xls", "").replaceAll(".*_", "");
			System.out.println("正在转换:" + className + " | " + fileName);
			String explain = fileName.replaceAll("_.*", "");
			try {
				parse(className, fileName, 0, explain);
			} catch (Exception e) {
				throw new RuntimeException("出错的表名:" + className);
			}
			System.gc();
		}
	}
	
	/**
	 * 转换
	 * @param className			生成类名
	 * @param fileName			生成文件名
	 */
	private static void parse(String className, String fileName, int sheetIndex, String explain) throws IOException {

		fileName = PATH + fileName;
		
		xlsReader sr = new xlsReader();
		Constent constent = sr.getConstent(fileName, sheetIndex, className);
		constent.setExplain(explain);
		
		JavaClassGenerator g1 = new JavaClassGenerator();
		JavaConfigClassGenerator g2 = new JavaConfigClassGenerator();
		XmlGenerator g3 = new XmlGenerator();
		ASClassGenerator g4 = new ASClassGenerator();
//		ASClassConfigGenerator g5 = new ASClassConfigGenerator();
		ASClassModelGenerator g6 = new ASClassModelGenerator();
		
		
		g1.generate(constent);
		g2.generate(constent);
		g3.generate(constent);
		g4.generate(constent);
		
//		g5.generate(constent);
		g6.generate(constent);
	}
}